{
  Плагины работы с базами данных

 TinlDBDriver -

   версия 0.1 март 2011 prodg@ya.ru D.Kondakov
}
unit IIntgrlDBPlgn;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IIntgrlTypes, IIntgrlBaseDefs, IIntgrlBaseCnfg, SQLite3DB, SQLDB;

{$I calcconfig.inc}

type

  { TinlDBDriver }

  TinlDBDriver = class(TinlPlugin)
    constructor Create(aName: TinlNameType; aSrc: TextLongNameType);
    destructor Destroy; override;
    function CheckParams: TinlLogicType; override;
    procedure ResetParams; override;
    procedure ProceedSignal(snlMsg: TinlStringType); override;
    procedure CloseBase;
  private
    FSrcName: TextLongNameType;
    FConnected: TinlLogicType;

  protected
    procedure DataInit; override;
    procedure DataDone; override;
    procedure ConnectDB; virtual; abstract;
    procedure CloseDB; virtual; abstract;
  end;

  TStorageType = (sSQLite, sSQServer, sFSFlat);

  { TSQLite3DBDriver }

  TSQLite3DBDriver = class(TinlDBDriver)
    constructor Create(aSrc: TextLongNameType);
    destructor Destroy; override;
    procedure AddDefParams(Params: TStringList); override;
  private
    FSQLDB: TSQLite;
  protected
    procedure ConnectDB; override;
    procedure CloseDB; override;
  end;

  { TMyDBDriver }

  TMyDBDriver = class(TinlDBDriver)
    constructor Create(aSrc: TextLongNameType);
  private
    FmSQLDB: TSQLConnection;
  protected
    procedure ConnectDB; override;
    procedure CloseDB; override;
  end;

  { TFSflatDBDriver }

  TFSflatDBDriver = class(TinlDBDriver)
    constructor Create(aSrc: TextLongNameType);

  protected
    procedure ConnectDB; override;
    procedure CloseDB; override;
  end;

implementation

{ TinlDBDriver }

constructor TinlDBDriver.Create(aName: TinlNameType; aSrc: TextLongNameType);
begin
  inherited Create(pgBase, aName);
  FConnected := false;
  FSrcName := aSrc;
end;

destructor TinlDBDriver.Destroy;
begin

  inherited Destroy;
end;

function TinlDBDriver.CheckParams: TinlLogicType;
begin
  Result := true;
end;

procedure TinlDBDriver.ResetParams;
begin
  //inherited ResetParams;
end;

procedure TinlDBDriver.ProceedSignal(snlMsg: TinlStringType);
begin
  //inherited ProceedSignal(snlMsg);
end;

procedure TinlDBDriver.CloseBase;
begin
  FConnected := false;
end;

procedure TinlDBDriver.DataInit;
begin
  ConnectDB;
end;

procedure TinlDBDriver.DataDone;
begin
  CloseDB;
end;

{ TSQLite3DBDriver }

constructor TSQLite3DBDriver.Create(aSrc: TextLongNameType);
begin
  inherited Create('SQLite3DB', aSrc);
  FSQLDB := TSQLite.Create(aSrc);
end;

destructor TSQLite3DBDriver.Destroy;
begin
  FreeAndNil(FSQLDB);
  inherited;
end;

procedure TSQLite3DBDriver.AddDefParams(Params: TStringList);
begin
  //inherited AddDefParams(Params);
end;

procedure TSQLite3DBDriver.ConnectDB;
begin
  //inherited ConnectDB;
end;

procedure TSQLite3DBDriver.CloseDB;
begin
  //inherited CloseDB;
end;

{ TMyDBDriver }

constructor TMyDBDriver.Create(aSrc: TextLongNameType);
begin
  inherited Create('MySQLDB', aSrc);

end;

procedure TMyDBDriver.ConnectDB;
begin
  //inherited ConnectDB;
end;

procedure TMyDBDriver.CloseDB;
begin
  //inherited CloseDB;
end;

{ TFSflatDBDriver }

constructor TFSflatDBDriver.Create(aSrc: TextLongNameType);
begin
  inherited Create('FSflatDB', aSrc);

end;

procedure TFSflatDBDriver.ConnectDB;
begin
  //inherited ConnectDB;
end;

procedure TFSflatDBDriver.CloseDB;
begin
  //inherited CloseDB;
end;

end.

